package lwk.lambda;

/**
 * @author:lwk
 * @create: 2022-07-27 22:20
 * @Description: Lambda测试
 */
public class TestLambda1 {

    // 3、静态内部类
    static class Like2 implements ILikeInterFace {
        @Override
        public void iLike() {
            System.out.println("i like lambda 2 !!");
        }
    }

    public static void main(String[] args) {

        ILikeInterFace like = new Like();
        like.iLike();

        like = new Like2();
        like.iLike();

        // 4、局部内部类
        class Like3 implements ILikeInterFace {
            @Override
            public void iLike() {
                System.out.println("i like lambda 3 !!");
            }
        }

        like = new Like3();
        like.iLike();

        // 5、匿名内部类,没有类的名称，必须借助接口或者父类
        like = new ILikeInterFace() {
            @Override
            public void iLike() {
                System.out.println("i like lambda 4 !!");
            }
        };
        like.iLike();

        // 6、用lambda简化
        like = () ->  {
            System.out.println("i like lambda 5 !!");
        };
        like.iLike();

    }
}

//1、定义一个函数式接口（只有一个方法）
interface ILikeInterFace {
    void iLike();
}

//2、实现类
class Like implements ILikeInterFace {
    @Override
    public void iLike() {
        System.out.println("i like lambda 1 !!");
    }
}